package com.traveldream.frontend.managed_beans;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.traveldream.entity_managers.BookingManager;
import com.traveldream.entity_managers.CustomerManager;
import com.traveldream.entity_managers.InviteManager;

import java.util.ArrayList;
import java.util.List;

import com.traveldream.entities.Booking;
import com.traveldream.entities.BookingPK;
import com.traveldream.entities.Invite;

/**
 *	customer controller managed bean
 *		- methods for getting customer bookings, invites and accepting invite packets
 */

@ManagedBean(name="customerFrontend")
@SessionScoped
public class CustomerBean {

	@EJB
	private BookingManager bm;
	@EJB
	private InviteManager im;
	@EJB
	private CustomerManager cm;
	
	List<Booking> bookingList;
	List<Invite>  inviteList;
	
	public CustomerBean(){
		
		bookingList = new ArrayList<Booking>();
		inviteList  = new ArrayList<Invite>();
	}
	
	public String acceptInvite(Invite i)
	{
		if(im.acceptInvite(i, cm.getAuthenticatedUser()))
			return "";
		else
			return "/booking/error";
	}
	
	
	public List<Booking> getBookingList(){
		
		bookingList = bm.findByCustomer(cm.getAuthenticatedUser());
		return bookingList;
	}
	
	public List<Invite> getInviteList(){
		
		inviteList = im.findByReceiver(cm.getAuthenticatedUser());
		return inviteList;
	}
}
